home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH04 / EX4_2.ASM < prev    next >
Encoding:
Assembly Source File  |  1996-02-03  |  3.7 KB  |  142 lines

  1. ; X86.ASM
  2. ;
  3. ; This is a special version of SHELL.ASM that includes macros for the x86 GET and PUT
  4. ; instructions.  It allows you to write x86 style programs for the 80x86.
  5. ;
  6. ; There are a few caveats.  
  7. ;
  8. ; First, you cannot use the HALT, BRK, or IRET instructions.
  9. ; BRK does not exist, HALT and IRET do not work the same way as they do on the x86
  10. ; hypothetical processors.
  11. ;
  12. ; Second, the memory-mapped I/O devices are not present (no switches, no LEDs).
  13. ;
  14. ; Third, use operands of the form "DS:[xxxx]" for the direct addressing mode.
  15. ; Without the "DS:" prefix, the instruction will not work the same way as the
  16. ; x86 instruction.
  17. ;
  18. ; Fourth, unlike the x86, this program uses separate segments for the code and
  19. ; data.  You cannot do self-modifying code like you did on the x86 assignments.
  20. ;
  21. ; Fifth, MASM lets you use labels that are just like the x86 labels with one exception:
  22. ; "C" is a reserved word in MASM so you cannot create a program label named "C".  MASM
  23. ; returns some bizarre error if you do.
  24. ;
  25. ; Sixth, you can use the x86 registers and addressing modes as well as the 80x86
  26. ; registers and addressing modes (8086 only). 
  27.  
  28.  
  29.         include     stdlib.a
  30.         includelib    stdlib.lib
  31.  
  32. sseg        segment    para stack 'stack'
  33. stk        byte    128 dup ("stack   ")
  34. sseg        ends
  35.  
  36. dseg        segment para public 'data'
  37. DataMemory    byte    65520 dup (?)
  38. dseg        ends
  39.  
  40.  
  41. cseg        segment    para public 'code'
  42.         assume    cs:cseg, ds:cseg
  43.  
  44.  
  45. ; The following assembly language procedure simulates the x86 GET instruction.
  46.  
  47. get        textequ    <call Gethex>
  48. GetHex        proc    near
  49.         push    es
  50.         push    bx
  51.         push    di
  52.  
  53. GHLoop:        print
  54.         byte    "Enter a hexadecimal number:",0
  55.         getsm
  56.         mov    bx, di
  57. TestHex:    mov    al, es:[bx]
  58.         inc    bx
  59.         cmp    al, 0
  60.         je    GoodHex
  61.         IsXDigit
  62.         je    TestHex
  63.         print
  64.         byte    "Illegal hexadecimal value, re-enter",cr,lf,0
  65.         jmp    GHLoop
  66.  
  67. GoodHex:    AtoH
  68.         free
  69.         pop    di
  70.         pop    bx
  71.         pop    es
  72.         ret
  73. GetHex        endp
  74.  
  75.     
  76.  
  77. ; The following assembly language procedure simulates the x86 PUT instruction.
  78.  
  79. put        textequ    <call PutHex>
  80. PutHex        proc    near
  81.         putw
  82.         putcr
  83.         ret
  84. PutHex        endp
  85.  
  86.  
  87.  
  88. ; This is where the main program goes.
  89.  
  90. Main        proc
  91.         mov    ax, dseg
  92.         mov    ds, ax
  93.         mov    es, ax
  94.         meminit
  95.  
  96.  
  97. ;*****************************************************************************************
  98. ;
  99. ; EX4_2: Perform all the tasks described in the comments that follow.
  100. ;
  101. ;*****************************************************************************************
  102.  
  103.  
  104. ; Remove this comment and replace it with an instruction that reads a hexadecimal
  105. ; value from the user, leaving that value in the AX register.
  106.  
  107. ; Replace this comment with an x86 instruction that copies the value in the AX register
  108. ; to the BX register.
  109.  
  110. ; Remove this comment and replace it with an instruction that reads a hexadecimal
  111. ; value from the user, leaving that value in the AX register.
  112.  
  113. ; Remove this comment and replace it with an instruction that adds the values in the
  114. ; AX and BX registers together, leaving their sum in AX.
  115.  
  116. ; Replace this comment with a line, that begins with the "a:" label, that prints the
  117. ; value in the ax register
  118.  
  119. ; Replace this comment with a line that subtracts one from the value in the AX register.
  120.  
  121. ; Replace this comment with a line that compares the value in the AX register to zero.
  122.  
  123. ; Replace this comment with a line that jumps back to label "a" if AX was greater than
  124. ; zero.
  125.  
  126. ; Replace this comment with a line that prints the value in the AX register.
  127.  
  128.  
  129. ;*****************************************************************************************
  130.  
  131.  
  132.         ExitPgm
  133. Main        endp
  134.  
  135. cseg        ends
  136.  
  137.  
  138. zzzzzzseg    segment    para public 'zzzzzz'
  139. LastBytes    byte    16 dup (?)
  140. zzzzzzseg    ends
  141.         end    Main
  142.